package jzqb.service.impl;


import jzqb.bo.SubscriptBo;
import jzqb.dao.SubscriptDao;
import jzqb.dao.SubscriptDataDao;
import jzqb.service.SubscriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 自用库业务层实现类
 */
@Service
public class SubscriptServiceImpl implements SubscriptService {

    @Autowired
    SubscriptService subscriptService;

    @Autowired
    SubscriptDao subscriptDao;

    @Autowired
    SubscriptDataDao subscriptDataDao;

    @Override
    public Boolean insertSubscript(SubscriptBo subscriptBo) {
        SubscriptBo subscript = subscriptService.selectSubscript(subscriptBo);
        if (subscript != null) {
            return false;
        } else {
            return subscriptDao.insertSubscript(subscriptBo);
        }
    }

    @Override
    public SubscriptBo selectSubscript(SubscriptBo subscriptBo) {
        return subscriptDao.selectSubscript(subscriptBo);
    }

    @Override
    public List<SubscriptBo> getAlreadySubscript(SubscriptBo subscriptBo) {
        return subscriptDao.getAlreadySubscript(subscriptBo);
    }

    @Override
    public Boolean deleteSubscriptById(SubscriptBo subscriptBo) {
        SubscriptBo subscript = subscriptDao.getSubscriptById(subscriptBo);
        //  在取消订阅的时候删除 已读数据。
        Boolean result = subscriptDataDao.deleteAllsubscriptData(subscript);
        return subscriptDao.deleteSubscriptById(subscriptBo);
    }
}
